<template>
  <base-breadcrumb>
    <div
      v-loading="spinning"
      ref="parentNode"
    >
      <a-form-model
        ref="form1"
        :model="form"
        :rules="rules"
      >
        <a-card :bordered="false">
          <title-name title="项目信息" />
          <a-row :gutter="24">
                        <a-col
                          :md="16"
                          :sm="16"
                        >
                          <a-form-model-item
                            label="所属单位"
                            :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                            :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
                          >
                            <!--                              v-model="form.branchCompanyName"-->
                            <BaseInput
                             :value='unit'
                              disabled
                            />
                          </a-form-model-item>
                        </a-col>
<!--            <a-col-->
<!--              :md="8"-->
<!--              :sm="8"-->
<!--            >-->
<!--              <a-form-model-item-->
<!--                label="分公司"-->
<!--                :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"-->
<!--                :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"-->
<!--              >-->
<!--                <BaseInput-->
<!--                  v-model="form.branchCompanyName"-->
<!--                  disabled-->
<!--                />-->
<!--              </a-form-model-item>-->
<!--            </a-col>-->
<!--            <a-col-->
<!--              :md="8"-->
<!--              :sm="8"-->
<!--            >-->
<!--              <a-form-model-item-->
<!--                label="项目名称"-->
<!--                :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"-->
<!--                :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"-->
<!--              >-->
<!--                <BaseInput-->
<!--                  v-model="form.projectName"-->
<!--                  disabled-->
<!--                />-->
<!--              </a-form-model-item>-->
<!--            </a-col>-->
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="项目编号"
                :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
              >
                <BaseInput
                  v-model="form.projectNum"
                  disabled
                />
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row :gutter="24">
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="项目经理"
                :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
              >
                <BaseInput
                  v-model="form.projectManager"
                  disabled
                />
              </a-form-model-item>
            </a-col>
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="日志日期"
                :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
              >
                <BaseInput
                  v-model="form.logDate"
                  disabled
                />
              </a-form-model-item>
            </a-col>
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="上午天气"
                :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
                prop="morningWeather"
              >
                <a-select
                  v-model="form.morningWeather"
                  placeholder="请选择"
                >
                  <a-select-option
                    v-for="item in weathers"
                    :key="item.id"
                    :value="item.id"
                  >
                    {{ item.name }}
                  </a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row :gutter="24">
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="下午天气"
                :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
                prop="afterNoonWeather"
              >
                <a-select
                  v-model="form.afterNoonWeather"
                  placeholder="请选择"
                >
                  <a-select-option
                    v-for="item in weathers"
                    :key="item.id"
                    :value="item.id"
                  >
                    {{ item.name }}
                  </a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="最高温度（˚C）"
                :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
                prop="temperatureMax"
              >
                <BaseInput
                  v-model="form.temperatureMax"
                  placeholder="请输入"
                  @input="checkInput"
                  @blur="maxTemperatures"
                />
              </a-form-model-item>
            </a-col>
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="最低温度（˚C）"
                :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
                prop="temperatureMin"
              >
                <BaseInput
                  v-model="form.temperatureMin"
                  placeholder="请输入"
                  @input="checkInputs"
                  @blur="minTemperatures"
                />
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row :gutter="24">
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="风力"
                :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
                prop="windPower"
              >
                <BaseInput
                  v-model="form.windPower"
                  :max-length="30"
                  placeholder="请输入"
                />
              </a-form-model-item>
            </a-col>
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="PM2.5"
                :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
              >
                <BaseInput
                  v-model="form.pm"
                  :max-length="30"
                  placeholder="请输入"
                  @keyup.native="proving()"
                />
              </a-form-model-item>
            </a-col>
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="有无突发事件"
                :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
                prop="whetherEmergency"
              >
                <a-select
                  v-model="form.whetherEmergency"
                  placeholder="请选择"
                  @change="isHaveEmergency"
                >
                  <a-select-option :value="0"> 无 </a-select-option>
                  <a-select-option :value="1"> 有 </a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row
            v-if="emergencyInfo"
            :gutter="24"
          >
            <a-col
              :md="24"
              :sm="24"
            >
              <a-form-model-item
                label="突发事件说明"
                :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
                prop="emergencyInstructions"
              >
                <BaseTextarea
                  v-model="form.emergencyInstructions"
                  :max-length="3000"
                  placeholder="请输入"
                />
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row :gutter="24">
            <a-col
              :md="24"
              :sm="24"
            >
              <a-form-model-item
                label="当天主要施工项目"
                :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
                prop="majorConstructionProjects"
              >
                <BaseTextarea
                  v-model="form.majorConstructionProjects"
                  :max-length="3000"
                  type="textarea"
                  placeholder="请输入"
                />
                备注：如无填写信息请填写"无"
              </a-form-model-item>
            </a-col>
          </a-row>

          <title-name title="生产情况记录（当日施工项目内容、机械作业、班组工作、生产存在问题）" />
          <div class="second-box">
            <title-name title="基本情况" />
            <!-- 只有劳务管理员才填写出勤人 -->
            <div
              v-if="isManager"
              style="margin-left: 30px"
              class="mb20"
            >
              <div
                class="mb12"
                style="font-size: 14px"
              >出勤人数：</div>
              <div class="mb12">
                <a-button
                  type="primary"
                  @click="$refs.dialogSubcontractors && ($refs.dialogSubcontractors.visible = true)"
                >增加分包商</a-button>
                <a-button
                  :disabled="!selectedRowKeys.length"
                  class="ml12"
                  type="primary"
                  @click="handleAddRow"
                >增加工种</a-button>
                <span
                  class="ml12"
                  style="color:red;"
                >请在【分包商进出场台账】中设置分包商的分部分项。</span>
              </div>
              <s-table
                ref="table"
                size="default"
                bordered
                row-key="id"
                :columns="columns"
                :data="loadData"
                :show-pagination="false"
                :scroll="{ y: 600 }"
                :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: handleSelect, type: 'radio' }"
              >
                <template slot="footer"> 总人数：{{ total }} </template>
                <!-- 工种 -->
                <a-select
                  slot="jobType"
                  v-model="text.id"
                  slot-scope="text, record"
                  :get-popup-container="() => $refs.parentNode"
                >
                  <a-select-option
                    v-for="item in jobList"
                    :key="item.id"
                    :value="item.id"
                    :disabled="jobDisabled(record.subcontractorsName, item.id) || item.disabled"
                  >{{ item.name }}</a-select-option>
                </a-select>
                <!-- 出勤人数 -->
                <BaseInputNumber
                  slot="attendanceNumber"
                  slot-scope="text, record"
                  :min="1"
                  :precision="0"
                  v-model="record.attendanceNumber"
                />
                <!-- 删除操作 -->
                <a-button
                  type="link"
                  slot="action"
                  slot-scope="text, record, index"
                  @click="handleRemove(index,record)"
                >删除</a-button>
              </s-table>
            </div>
            <a-row :gutter="24">
              <a-col
                :md="24"
                :sm="24"
              >
                <a-form-model-item
                  class="titleLabel"
                  label="机械、设备使用情况（主要机械情况）"
                  :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                  :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
                  prop="equipmentUsage"
                >
                  <BaseTextarea
                    v-model="form.equipmentUsage"
                    :max-length="3000"
                    placeholder="请输入"
                  />
                  备注：如无填写信息请填写"无"
                </a-form-model-item>
              </a-col>
            </a-row>

            <title-name title="工作内容" />
            <a-row :gutter="24">
              <a-col
                :md="24"
                :sm="24"
              >
                <a-form-model-item
                  class="titleLabel"
                  label="当天施工内容实际完成情况及主要工程量"
                  :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                  :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
                  prop="majorWorks"
                >
                  <BaseTextarea
                    v-model="form.majorWorks"
                    :max-length="3000"
                    placeholder="请输入"
                  />
                  备注：如无填写信息请填写"无"
                </a-form-model-item>
              </a-col>
            </a-row>
            <a-row :gutter="24">
              <a-col
                :md="24"
                :sm="24"
              >
                <a-form-model-item
                  class="titleLabel"
                  label="使用的主要材料规格、数量（日消耗量）"
                  :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                  :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
                  prop="materialUsage"
                >
                  <BaseTextarea
                    v-model="form.materialUsage"
                    :max-length="3000"
                    placeholder="请输入"
                  />
                  备注：如无填写信息请填写"无"
                </a-form-model-item>
              </a-col>
            </a-row>
            <a-row :gutter="24">
              <a-col
                :md="24"
                :sm="24"
              >
                <a-form-model-item
                  class="titleLabel"
                  label="施工现场有关会议内容（主要简要概述）"
                  :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                  :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
                  prop="constructionSiteMeetingContent"
                >
                  <BaseTextarea
                    v-model="form.constructionSiteMeetingContent"
                    :max-length="3000"
                    placeholder="请输入"
                  />
                  备注：如无填写信息请填写"无"
                </a-form-model-item>
              </a-col>
            </a-row>
            <a-row :gutter="24">
              <a-col
                :md="24"
                :sm="24"
              >
                <a-form-model-item
                  label="试块制作情况"
                  :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                  :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
                  prop="productionOfTestBlock"
                >
                  <BaseTextarea
                    v-model="form.productionOfTestBlock"
                    :max-length="3000"
                    placeholder="请输入"
                  />
                  备注：如无填写信息请填写"无"
                </a-form-model-item>
              </a-col>
            </a-row>
            <a-row :gutter="24">
              <a-col
                :md="24"
                :sm="24"
              >
                <a-form-model-item
                  class="titleLabel"
                  label="材料进场、送检情况及当日取回试验报告编号及结果"
                  :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                  :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
                  prop="materialConditions"
                >
                  <BaseTextarea
                    v-model="form.materialConditions"
                    :max-length="3000"
                    placeholder="请输入"
                  />
                  备注：如无填写信息请填写"无"
                </a-form-model-item>
              </a-col>
            </a-row>

            <title-name title="技术质量安全工作记录（技术质量安全活动、技术质量安全问题、检查验收情况等）" />
            <a-row :gutter="24">
              <a-col
                :md="24"
                :sm="24"
              >
                <a-form-model-item
                  class="titleLabel"
                  label="建设单位及监理单位对本工程实施工提出的技术、质量、安全、进度要求、意见及采纳实施情况"
                  :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                  :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
                  prop="implementation"
                >
                  <BaseTextarea
                    v-model="form.implementation"
                    :max-length="3000"
                    placeholder="请输入"
                  />
                  备注：如无填写信息请填写"无"
                </a-form-model-item>
              </a-col>
            </a-row>
            <a-row
              :gutter="24"
              style="margin-top: 15px"
            >
              <a-col
                :md="24"
                :sm="24"
              >
                <a-form-model-item
                  class="titleLabel"
                  label="往来函件（设计变更、洽商记录、工程联系单等文件编号及内容简要概述）"
                  :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                  :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
                  prop="currentLetter"
                >
                  <BaseTextarea
                    v-model="form.currentLetter"
                    :max-length="3000"
                    placeholder="请输入"
                  />
                  备注：如无填写信息请填写"无"
                </a-form-model-item>
              </a-col>
            </a-row>
            <title-name title="检查情况" />
            <a-row :gutter="24">
              <a-col
                :md="24"
                :sm="24"
              >
                <a-form-model-item
                  class="titleLabel"
                  label="质量自检情况及整改措施"
                  :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                  :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
                  prop="qualitySelfInspectionAndCorrectiveAction"
                >
                  <BaseTextarea
                    v-model="form.qualitySelfInspectionAndCorrectiveAction"
                    :max-length="3000"
                    placeholder="请输入"
                  />
                  备注：如无填写信息请填写"无"
                </a-form-model-item>
              </a-col>
            </a-row>
            <a-row :gutter="24">
              <a-col
                :md="24"
                :sm="24"
              >
                <a-form-model-item
                  class="titleLabel"
                  label="监理单位对相应工程部位的检查结果"
                  :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                  :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
                  prop="supervisionInspectionResults"
                >
                  <BaseTextarea
                    v-model="form.supervisionInspectionResults"
                    :max-length="3000"
                    placeholder="请输入"
                  />
                  备注：如无填写信息请填写"无"
                </a-form-model-item>
              </a-col>
            </a-row>
            <a-row :gutter="24">
              <a-col
                :md="24"
                :sm="24"
              >
                <a-form-model-item
                  label="安全"
                  :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                  :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
                  prop="safety"
                >
                  <BaseTextarea
                    v-model="form.safety"
                    :max-length="3000"
                    placeholder="请输入"
                  />
                  备注：如无填写信息请填写"无"
                </a-form-model-item>
              </a-col>
            </a-row>
            <a-row :gutter="24">
              <a-col
                :md="24"
                :sm="24"
              >
                <a-form-model-item
                  class="titleLabel"
                  label="监理通知单情况（主要简要概述）"
                  :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                  :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
                  prop="supervisionNoticeSituation"
                >
                  <BaseTextarea
                    v-model="form.supervisionNoticeSituation"
                    :max-length="3000"
                    placeholder="请输入"
                  />
                  备注：如无填写信息请填写"无"
                </a-form-model-item>
              </a-col>
            </a-row>
            <a-row :gutter="24">
              <a-col
                :md="24"
                :sm="24"
              >
                <a-form-model-item
                  class="titleLabel"
                  label="监理安全隐患整改回复情况（主要内容简要概述）"
                  :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                  :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
                  prop="safetyRiskRectificationNotice"
                >
                  <BaseTextarea
                    v-model="form.safetyRiskRectificationNotice"
                    :max-length="3000"
                    placeholder="请输入"
                  />
                  备注：如无填写信息请填写"无"
                </a-form-model-item>
              </a-col>
            </a-row>
            <a-row :gutter="24">
              <a-col
                :md="24"
                :sm="24"
              >
                <a-form-model-item
                  class="titleLabel"
                  label="安全文明施工、环保等检查情况"
                  :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                  :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
                  prop="safetyCivilizedConstructionInspection"
                >
                  <BaseTextarea
                    v-model="form.safetyCivilizedConstructionInspection"
                    :max-length="3000"
                    placeholder="请输入"
                  />
                  备注：如无填写信息请填写"无"
                </a-form-model-item>
              </a-col>
            </a-row>
            <a-row :gutter="24">
              <a-col
                :md="24"
                :sm="24"
              >
                <a-form-model-item
                  class="titleLabel"
                  label="其他情况（如有上级或其他单位的安全质量检查情况）"
                  :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                  :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
                  prop="otherSituations"
                >
                  <BaseTextarea
                    v-model="form.otherSituations"
                    :max-length="3000"
                    placeholder="请输入"
                  />
                  备注：如无填写信息请填写"无"
                </a-form-model-item>
              </a-col>
            </a-row>
            <a-row :gutter="24">
              <a-col
                :md="8"
                :sm="8"
              >
                <a-form-model-item
                  label="填写人"
                  :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                  :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
                >
                  <BaseInput
                    v-model="form.writtenBy"
                    disabled
                  />
                </a-form-model-item>
              </a-col>
              <a-col
                :md="8"
                :sm="8"
              >
                <a-form-model-item
                  label="填写时间"
                  :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                  :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
                >
                  <BaseInput
                    v-model="form.writeTime"
                    disabled
                  />
                </a-form-model-item>
              </a-col>
            </a-row>
          </div>
        </a-card>

        <a-card style="margin-bottom: 50px">
          <title-name title="相关附件上传(提示：单个文件上传大小需不超过200M )" />
          <!-- 责任区域的主责任人才能显示 -->
          <a-form-model-item
            v-if="isResponsible === 1"
            label="当日整体形象航拍照片"
            :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
            :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
            prop="aerialPhotoFileList"
          >
            <l-table
              uploadType="image"
              business-code="PM20"
              editModel="1"
              isMultiple
              :upload-arrys.sync="form.aerialPhotoFileList"
              @fileArrysData="handleFileChange('aerialPhotoFileList', 'aerialPhotoFileIds')"
            ></l-table>
            <ellipsis
              tooltip
              :length="12"
              class="fileItem"
              v-for="(item, index) in form.aerialPhotoFileList"
              :key="index"
            >{{ item.name || item.fileName }}</ellipsis>
          </a-form-model-item>
          <a-form-model-item
            label="室内代表性部位施工进度照片"
            :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
            :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
            prop="progressPhotoFileList"
          >
            <l-table
              uploadType="image"
              business-code="PM20"
              editModel="1"
              :upload-arrys.sync="form.progressPhotoFileList"
              isMultiple
              @fileArrysData="handleFileChange('progressPhotoFileList', 'progressPhotoFileIds')"
            ></l-table>
            <ellipsis
              tooltip
              :length="12"
              class="fileItem"
              v-for="(item, index) in form.progressPhotoFileList"
              :key="index"
            >{{ item.name || item.fileName }}</ellipsis>
          </a-form-model-item>
          <a-form-model-item
            label="其他附件"
            :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
            :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
            prop="fileIds"
          >
            <l-table
              uploadType="list"
              :needChineseName="true"
              business-code="PM20"
              editModel="1"
              :upload-arrys.sync="form.fileArrays"
              isMultiple
              @fileArrysData="handleFileChange('fileArrays', 'fileIds')"
            ></l-table>
          </a-form-model-item>
        </a-card>
      </a-form-model>
    </div>

    <div
      class="btn_box page-btn-right-top"
    >
      <a-button
        type="primary"
        :loading="loadingState.DRAFT"
        @click="saveDraft"
      > 保存草稿 </a-button>
      <a-button
        type="primary"
        :loading="loadingState.SUBMITTED"
        class="ml12"
        @click="submit"
      > 提交 </a-button>
      <a-button
        type="primary"
        class="ml12"
        @click="goBack"
      > 关闭 </a-button>
    </div>
    <!-- 选择分包商 -->
    <DialogSubcontractors
      ref="dialogSubcontractors"
      @createList="handleAddSub"
      :selectedKeys="selectedKeys"
    />
  </base-breadcrumb>
</template>

<script>
import { STable, Ellipsis } from '@/components'
import { getLogAdd, getLogEditDetails } from '@/api/project/constructionLog'
import { getTypes } from '@/api/commons'
import DialogSubcontractors from './components/DialogSubcontractors' // 选择分包商
import ARow from 'ant-design-vue/es/grid/Row'
import { getLabel } from '@/api/project/projects'

const columns = [
  {
    title: '序号',
    width: 65,
    customRender() {
      return arguments[2] + 1
    }
  },
  {
    title: '分包商',
    dataIndex: 'subcontractorsName'
  },
  {
    title: '分部分项',
    dataIndex: 'partialAllName'
  },
  {
    title: '工种',
    dataIndex: 'jobType',
    scopedSlots: { customRender: 'jobType' }
  },
  {
    title: '人数',
    dataIndex: 'attendanceNumber',
    scopedSlots: { customRender: 'attendanceNumber' }
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: 100,
    scopedSlots: { customRender: 'action' }
  }
]
export default {
  name: 'a' + Date.now(),
  components: {
    ARow,
    Ellipsis,
    STable,
    DialogSubcontractors
  },
  data() {
    this.columns = columns
    return {
      spinning: false, // 全局loading
      loadingState: {
        DRAFT: false,
        SUBMITTED: false
      },
      loadData: () => {
        return Promise.resolve({
          code: 200,
          data: this.form.attendanceList || []
        })
      }, // 出勤人数回调
      jobList: [], // 工种
      uploadArrys: [],
      weathers: [], // 天气数据
      data: [],
      form: {
        writtenBy: JSON.parse(sessionStorage.getItem('ycloud-user_info')).name,
        writeTime: '',
        whetherEmergency: ''
      },

      rules: {
        morningWeather: [{ required: true, message: '请选择上午天气', trigger: 'change' }],
        afterNoonWeather: [{ required: true, message: '请选择下午天气', trigger: 'change' }],
        temperatureMax: [{ required: true, message: '请输入最高温度', trigger: 'change' }],
        temperatureMin: [{ required: true, message: '请输入最低温度', trigger: 'change' }],
        windPower: [{ required: true, message: '请输入风力', trigger: 'blur' }],
        emergencyInstructions: [{ required: true, message: '请输入突发事件说明', trigger: 'blur' }],
        majorConstructionProjects: [{ required: true, message: '请输入当天主要施工项目', trigger: 'blur' }],
        attendanceNumber: [{ required: true, message: '请输入出勤人数', trigger: 'blur' }],
        headcount: [{ required: true, message: '请输入总人数', trigger: 'blur' }],
        equipmentUsage: [{ required: true, message: '请输入机械、设备使用情况', trigger: 'blur' }],
        majorWorks: [{ required: true, message: '请输入当天施工内容实际完成情况', trigger: 'blur' }],
        materialUsage: [{ required: true, message: '请输入使用的主要材料规格、数量', trigger: 'blur' }],
        constructionSiteMeetingContent: [{ required: true, message: '请输入施工现场有关会议', trigger: 'blur' }],
        productionOfTestBlock: [{ required: true, message: '请输入试块制作情况', trigger: 'blur' }],
        materialConditions: [{ required: true, message: '请输入材料进场、送检情况', trigger: 'blur' }],
        implementation: [
          {
            required: true,
            message: '请输入建设单位及监理单位对本工程实施工提出的技术、质量、安全、进度要求、意见及采纳实施情况',
            trigger: 'blur'
          }
        ],
        currentLetter: [{ required: true, message: '请输入往来函件', trigger: 'blur' }],
        qualitySelfInspectionAndCorrectiveAction: [{ required: true, message: '请输入质量自检情况及整改措施', trigger: 'blur' }],
        supervisionInspectionResults: [{ required: true, message: '请输入监理单位对相应工程部位的检查结果', trigger: 'blur' }],
        safety: [{ required: true, message: '请输入安全', trigger: 'blur' }],
        supervisionNoticeSituation: [{ required: true, message: '请输入监理通知单情况', trigger: 'blur' }],
        safetyRiskRectificationNotice: [{ required: true, message: '请输入监理安全隐患整改回复情况', trigger: 'blur' }],
        safetyCivilizedConstructionInspection: [{ required: true, message: '请输入安全文明施工、环保等检查情况', trigger: 'blur' }],
        otherSituations: [{ required: true, message: '请输入其他情况（如有上级或其他单位的安全质量检查情况）', trigger: 'blur' }],
        whetherEmergency: [{ required: true, message: '请选择有无突发事件', trigger: 'change' }],
        aerialPhotoFileList: [{ required: true, type: 'array', message: '请上传当日整体形象航拍照片', trigger: 'change' }],
        progressPhotoFileList: [{ required: true, type: 'array', message: '请上传室内代表性部位施工进度照片', trigger: 'change' }]
      },

      dels: {},

      // 附件上传
      listUrl: '',
      deleteUrl: '/cscec-project-business/file/business/project-fileDelete',
      uploadList: '/cscec-project-business/file/business/fileUpload',
      businessId: '',

      queryParams: {
        id: '',
        assessmentTime: ''
      },
      logId: '',
      emergencyInfo: false,
      selectedRowKeys: [],
      selectedRows: [],
      isResponsible: null,
      unit: ''
    }
  },
  computed: {
    // 出勤选中行
    selectedKeys() {
      let ids = this.form.attendanceList?.map((i) => i?.subcontractorsId)
      return ids ? [...new Set(ids)] : []
    },
    // 出勤总人数
    total() {
      return this.form?.attendanceList?.length ? this.form.attendanceList.map((i) => i?.attendanceNumber)?.reduce((total, pre) => (total || 0) + (pre || 0)) : 0
    },
    // 岗位列表中是否有劳务工程师
    isManager() {
      console.log(this.$store.state.user.userInfo?.employee?.posts,'employee?.posts')
      return this.$store.state.user.userInfo?.employee?.posts.some((i) => i.code === 'PDPMLWGLY' && i.orgParentId === this.form.projectDeptOrgId)
    }
  },
  created() {
    this.logId = this.$route.query.logId
    this.queryParams.id = this.$route.query.logId

    this.getLogEditDetails()
    this.getTypes()
    this.getJob()
  },
  methods: {
    /**
     * @description: 删除出勤人行
     * @param {number} index：索引值
     * @param {object} record 行数据
     */
    handleRemove(index, record) {
      this.$confirm({
        title: '提示',
        content: '是否要删除数据？',
        onOk: () => {
          this.form.attendanceList = this.form.attendanceList.filter((el, i) => i !== index)
          // 删除选中项
          if (this.selectedRowKeys.includes(record.id)) {
            this.selectedRowKeys = []
          }
          this.search()
        }
      })
    },
    /**
     * @description: 出勤人表格选中行操作
     * @param {*} e：行对象
     */
    handleSelect(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    /**
     * @description: 禁用分包商出自己以外其他已选工种
     * @param {*} name：分包商名称
     * @param {*} id：当前选择项id
     */
    jobDisabled(name, id) {
      let chooseList = this.form.attendanceList?.filter((i) => i.subcontractorsName === name)?.map((i) => i.jobType?.id) // 当前分包商已选工种id集合
      return chooseList.includes(id)
    },
    /**
     * @description: 获取工种
     */
    getJob() {
      // isReturnNotUse是否返回不可用状态（1：返回）
      getLabel({ type: 37, isReturnNotUse: 1 }).then((res) => {
        if (res.code === 200) {
          this.jobList = res.data
        }
      })
    },
    /**
     * @description: 新增工种
     */
    handleAddRow() {
      let row = this.$clone(this.selectedRows[0])
      row.id = Date.now()
      row.jobType.id = void 0
      row.attendanceNumber = void 0
      this.form.attendanceList.splice(this.form.attendanceList.findIndex((el) => el.id === this.selectedRowKeys[0]) + 1, 0, row)
      this.search()
    },
    /**
     * @description: 新增分包商
     * @param {*} row：分包商信息
     * @return {*}
     */
    handleAddSub(row) {
      if (row.length <= 0) return
      // 根据分部分项成员添加表格数据
      let list = row[0].partialAllNameList.map((el, index) => ({ ...row[0], id: Date.now() + index, jobType: { id: el.id }, subcontractorsName: row[0].subcontractors, partialAllName: el }))
      this.form.attendanceList = list.concat(this.form.attendanceList || [])
      this.search()
    },
    /**
     * @description: 重置出勤人数表格
     */
    search() {
      this.$refs.table?.refresh(true)
    },
    /**
     * @description: 触发表单校验
     * @param {String} name：附件字段名
     * @param {String} replaceName：附件ids的字段名
     * @return {*}
     */
    handleFileChange(name, replaceName) {
      if (replaceName && this.form[name]?.length) {
        this.form[replaceName] = this.form[name].map((item) => item.commonId)
      }
      // 除其他附件，都需要校验
      if (name !== 'fileArrays') {
        this.$nextTick(() => {
          this.$refs.form1?.validateField(name)
        })
      }
    },
    handleInput2(e) {
      // 通过正则过滤小数点后两位
      e.target.value = e.target.value.match(/^\d*(\.?\d{0,1})/g)[0] || null
    },
    minTemperatures(e) {
      let minTem = e.target.value
      if (this.form.temperatureMax && parseFloat(this.form.temperatureMax) < parseFloat(minTem)) {
        this.form.temperatureMin = ''
        this.$message.error('最低温度不能高于最高温度！')
        return
      }
    },
    maxTemperatures(e) {
      let maxTem = e.target.value
      if (this.form.temperatureMin && parseFloat(maxTem) < parseFloat(this.form.temperatureMin)) {
        this.form.temperatureMax = ''
        this.$message.error('最高温度不能低于最低温度！')
        return
      }
    },
    checkInput() {
      this.form.temperatureMax = this.dealInputVal(this.form.temperatureMax)
    },
    checkInputs() {
      this.form.temperatureMin = this.dealInputVal(this.form.temperatureMin)
    },
    dealInputVal(value) {
      var t = value.charAt(0)
      //先把非数字的都替换掉，除了数字和.
      value = value.replace(/[^\d.]/g, '')
      //必须保证第一个为数字而不是.
      value = value.replace(/^\./g, '')
      //保证只有出现一个.而没有多个.
      value = value.replace(/\.{2,}/g, '.')
      //保证.只出现一次，而不能出现两次以上
      value = value.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')
      value = value.replace(/^(\-)*(\d*)\.(\d\d).*$/, '$1$2.$3')
      value = value.indexOf('.') > 0 ? value.split('.')[0].substring(0, 5) + '.' + value.split('.')[1] : value.substring(0, 5)
      //如果第一位是负号，则允许添加   如果不允许添加负号 可以把这块注释掉
      if (t == '-') {
        value = '-' + value
      }
      return value
    },

    proving() {
      // this.form.pm 是input的值
      // 先把非数字的都替换掉，除了数字和.
      this.form.pm = this.form.pm.replace(/[^\d.]/g, '')
      // 必须保证第一个为数字而不是.
      this.form.pm = this.form.pm.replace(/^\./g, '')
      // 保证只有出现一个.而没有多个.
      this.form.pm = this.form.pm.replace(/\.{2,}/g, '')
      // 保证.只出现一次，而不能出现两次以上
      this.form.pm = this.form.pm.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')
      let index = -1
      for (let i in this.form.pm) {
        if (this.form.pm[i] === '.') {
          index = i
        }
        if (index !== -1) {
          if (i - index > 1) {
            this.form.pm = this.form.pm.substring(0, this.form.pm.length - 1)
          }
        }
      }
    },
    //控制只能输入小数点后2位
    clearNoNum(obj, val) {
      obj.value = obj.value.replace(/[^\d.]/g, '') //清除“数字”和“.”以外的字符
      obj.value = obj.value.replace(/\.{2,}/g, '.') //只保留第一个. 清除多余的
      obj.value = obj.value.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')
      obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3') //只能输入两个小数
      if (obj.value.indexOf('.') < 0 && obj.value != '') {
        //以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
        obj.value = parseFloat(obj.value)
      }
    },

    getLogEditDetails() {
      let that = this
      that.spinning = true
      getLogEditDetails({ id: that.logId })
        .then((res) => {
          that.spinning = false
          that.form = res.data
          that.unit = that.form.branchCompanyName +'/'+ that.form.projectName
          this.isResponsible = res.data.isResponsible
          if (that.form.afterNoonWeather == null) {
            that.form.afterNoonWeather = undefined
          }
          if (that.form.morningWeather == null) {
            that.form.morningWeather = undefined
          }
          if (that.form.whetherEmergency == null) {
            that.form.whetherEmergency = undefined
          }
          if (that.form.whetherEmergency == 1) {
            that.emergencyInfo = true
          } else {
            that.emergencyInfo = false
          }
          that.uploadArrys = res.data.fileArrays
          that.form.writtenBy = JSON.parse(sessionStorage.getItem('ycloud-user_info')).name
          that.form.writeTime = that.getNowDate()
          // 设置当日整体形象航拍照片默认空数组
          that.$set(that.form, 'aerialPhotoFileList', that.form.aerialPhotoFileList || [])
          // 设置室内代表性部位施工进度照片默认空数组
          that.$set(that.form, 'progressPhotoFileList', that.form.progressPhotoFileList || [])
          // 设置其他附件默认空数组
          that.$set(that.form, 'fileIds', that.form.fileIds || [])
          // 设置考勤人员默认空数组
          if (this.isManager) {
            that.$set(
              that.form,
              'attendanceList',
              (that.form.attendanceList?.length &&
                that.form.attendanceList.map((item) => {
                  // 添加工种空对象，防止columns找不到工种表头
                  if (!item.jobType) {
                    item.jobType = {
                      id: ''
                    }
                  }
                  return item
                })) ||
                []
            )
            that.search()
          }
          const keyList = [
            'majorConstructionProjects',
            // 'attendanceNumber',
            'equipmentUsage',
            'majorWorks',
            'materialUsage',
            'constructionSiteMeetingContent',
            'productionOfTestBlock',
            'materialConditions',
            'implementation',
            'currentLetter',
            'qualitySelfInspectionAndCorrectiveAction',
            'supervisionInspectionResults',
            'safety',
            'supervisionNoticeSituation',
            'safetyRiskRectificationNotice',
            'safetyCivilizedConstructionInspection',
            'otherSituations'
          ]
          keyList.forEach((key) => {
            that.$set(that.form, key, that.form[key] || '无')
          })
        })
        .catch(() => {
          that.spinning = false
        })
    },
    getTypes() {
      let that = this
      getTypes({ type: 19 }).then((res) => {
        that.weathers = res.data
      })
    },
    goBack() {
      this.$multiTab.close(this.$route.fullpath)
    },
    fileArrysData(val) {
      this.form.fileArrays = val
    },

    isHaveEmergency(val) {
      if (val == '1') {
        this.emergencyInfo = true
      } else {
        this.emergencyInfo = false
      }
    },
    submit() {
      // 提交
      let that = this
      that.form.id = that.logId
      that.form.writeStatus = 1
      that.$refs.form1.validate((err, value) => {
        if (err) {
          if (this.loadingState.SUBMITTED) return
          // 只有劳务管理员才校验出勤人
          if (this.isManager) {
            if (!that.form.attendanceList?.length) {
              that.$message.warning('请添加分包商出勤人数')
              return
            }
            for (let index in that.form.attendanceList) {
              if (!that.form.attendanceList[index].attendanceNumber) {
                that.$message.warning(`出勤人表格第${index + 1}行人数不能低于1人！`)
                // 滚动到表格处
                that.$refs.parentNode.parentNode.parentNode.scrollTop = that.$refs.table.$el.offsetTop
                return
              }
              if (!that.form.attendanceList[index]?.jobType?.id) {
                that.$message.warning(`出勤人表格第${index + 1}行工种不能为空！`)
                // 滚动到表格处
                that.$refs.parentNode.parentNode.parentNode.scrollTop = that.$refs.table.$el.offsetTop
                return
              }
            }
          }
          that.form.majorConstructionProjects == '无' ? (that.form.majorConstructionProjects = null) : null
          that.form.attendanceNumber == '无' ? (that.form.attendanceNumber = null) : null
          that.form.equipmentUsage == '无' ? (that.form.equipmentUsage = null) : null
          that.form.majorWorks == '无' ? (that.form.majorWorks = null) : null
          that.form.materialUsage == '无' ? (that.form.materialUsage = null) : null
          that.form.constructionSiteMeetingContent == '无' ? (that.form.constructionSiteMeetingContent = null) : null
          that.form.productionOfTestBlock == '无' ? (that.form.productionOfTestBlock = null) : null
          that.form.materialConditions == '无' ? (that.form.materialConditions = null) : null
          that.form.implementation == '无' ? (that.form.implementation = null) : null
          that.form.currentLetter == '无' ? (that.form.currentLetter = null) : null
          that.form.qualitySelfInspectionAndCorrectiveAction == '无' ? (that.form.qualitySelfInspectionAndCorrectiveAction = null) : null
          that.form.supervisionInspectionResults == '无' ? (that.form.supervisionInspectionResults = null) : null
          that.form.safety == '无' ? (that.form.safety = null) : null
          that.form.supervisionNoticeSituation == '无' ? (that.form.supervisionNoticeSituation = null) : null
          that.form.safetyRiskRectificationNotice == '无' ? (that.form.safetyRiskRectificationNotice = null) : null
          that.form.safetyCivilizedConstructionInspection == '无' ? (that.form.safetyCivilizedConstructionInspection = null) : null
          that.form.otherSituations == '无' ? (that.form.otherSituations = null) : null

          let form = that.$clone(that.form)
          if (form.aerialPhotoFileList?.length) {
            form.aerialPhotoFileIds = form.aerialPhotoFileList.map((i) => i.commonId)
            delete form.aerialPhotoFileList
          }
          if (form.progressPhotoFileList?.length) {
            form.progressPhotoFileIds = form.progressPhotoFileList.map((i) => i.commonId)
            delete form.progressPhotoFileList
          }
          if (form.fileArrays?.length) {
            form.fileIds = form.fileArrays.map((i) => i.commonId)
            delete form.fileArrays
          }
          that.loadingState.SUBMITTED = true
          getLogAdd(form)
            .then((res) => {
              that.loadingState.SUBMITTED = false
              if (res.code == 200 || res.data.code == 200) {
                that.$message.success('提交成功！')
                that.form = {}
                that.$multiTab.close(that.$route.fullpath)
              }
            })
            .catch(() => {
              that.loadingState.SUBMITTED = false
            })
        } else {
          // 滚动到顶部
          // that.$refs.parentNode.parentNode.parentNode.scrollTop = 0
          that.$message.warning('表单填写有误')
        }
      })
    },
    saveDraft() {
      if (this.loadingState.DRAFT) return
      this.form.writeStatus = 0
      this.form.id = this.logId
      // if (this.form.attendanceList?.length) {
      //   for (let index in this.form.attendanceList) {
      //     if (!this.form.attendanceList[index].attendanceNumber) {
      //       this.$message.warning(`出勤人表格第${Number(index) + 1}行人数不能低于1人！`)
      //       return
      //     }
      //   }
      this.loadingState.DRAFT = true
      let form = this.$clone(this.form)
      if (form.aerialPhotoFileList?.length) {
        form.aerialPhotoFileIds = form.aerialPhotoFileList.map((i) => i.commonId)
        delete form.aerialPhotoFileList
      }
      if (form.progressPhotoFileList?.length) {
        form.progressPhotoFileIds = form.progressPhotoFileList.map((i) => i.commonId)
        delete form.progressPhotoFileList
      }
      if (form.fileArrays?.length) {
        form.fileIds = form.fileArrays.map((i) => i.commonId)
        delete form.fileArrays
      }
      getLogAdd(form)
        .then((res) => {
          this.loadingState.DRAFT = false
          if (res.code == 200 || res.data.code == 200) {
            this.$message.success('保存成功！')
            this.form.detailsId = res.data.detailsId
          }
        })
        .catch(() => {
          this.loadingState.DRAFT = false
        })
      // } else {
      //   this.$message.warning('请添加分包商出勤人数')
      // }
    }
  }
}
</script>


<style>
.titleLabel textarea.ant-input {
  max-width: 100%;
  height: auto;
  min-height: 115px;
  line-height: 1.5;
  vertical-align: bottom;
  transition: all 0.3s, height 0s;
}
.fileItem {
  text-align: center;
  display: inline-block;
  width: 104px;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-right: 8px;
}
.second-box .titleName {
  font-size: 14px !important;
  margin-left: 12px;
}
</style>
